<?php

/**
 * \file
 * Classe `Date`.
 */

namespace pilar\SimpleFormMembers /* \cond */ ; /* \endcond */
{

/**
 * Membre de date.
 *
 * \since 22/09/2008
 * \author Matthieu OVIEDO <matthieu.oviedo@gmail.com>
 */
class Date extends \pilar\Forms\Member {

protected function initialize() {
 parent::initialize();
 
 $this->joinField('D'); // Jour.
 $this->joinField('M'); // Mois.
 $this->joinField('Y'); // Année.
}


public function guiDomNode($domDoc) {
 $domGui = $domDoc->createElement('gui');

 $domDay = $domDoc->createElement('input');
 $domDay->setAttribute('id', $this->globalId('D'));
 $domDay->setAttribute('name', $this->globalId('D'));
 $domDay->setAttribute('size', 2);
 $domDay->setAttribute('maxlength', 2);
 $domDay->setAttribute('title', $this->get('label').' (jour)');
 $domGui->appendChild($domDay);

 $domGui->appendChild($domDoc->createTextNode(' / '));

 $domMonth = $domDoc->createElement('input');
 $domMonth->setAttribute('id', $this->globalId('M'));
 $domMonth->setAttribute('name', $this->globalId('M'));
 $domMonth->setAttribute('size', 2);
 $domMonth->setAttribute('maxlength', 2);
 $domMonth->setAttribute('title', $this->get('label').' (mois)');
 $domGui->appendChild($domMonth);

 $domGui->appendChild($domDoc->createTextNode(' / '));

 $domYear = $domDoc->createElement('input');
 $domYear->setAttribute('id', $this->globalId('Y'));
 $domYear->setAttribute('name', $this->globalId('Y'));
 $domYear->setAttribute('size', 4);
 $domYear->setAttribute('maxlength', 4);
 $domYear->setAttribute('title', $this->get('label').' (année)');
 $domGui->appendChild($domYear);

 return $domGui;
}


protected function outputGuiController() { ?>
<?php foreach($this->fieldNames() as $f) { ?>
<?php  if($this->value($f) != '') { ?>
$('#<?php echo $this->globalId($f) ?>').val('<?php echo $this->value($f) ?>');
<?php  } ?>
<?php  if($this->status() == 'invalid') { ?>
$('#<?php echo $this->globalId($f) ?>').addClass('invalid');
<?php  } ?>
<?php } ?>
<?php
}

} // Class.

} // Namespace.

?>
